package com.homework;

import java.util.concurrent.CompletableFuture;

public class CompletableFuture01 {
    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        System.out.println("Main Thread Start!");

        CompletableFuture<String> cf = new CompletableFuture<>();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000L);
                    cf.complete("123456");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

        System.out.println("异步处理结果为：" + cf.get());

        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");

        System.out.println("Main Thread End!");
    }
}
